package cn.edu.cdu.health.service.impl;

import cn.edu.cdu.health.entity.Medicine;
import cn.edu.cdu.health.mapper.MedicineMapper;
import cn.edu.cdu.health.service.MedicineService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

@Service
public class MedicineServiceImpl extends ServiceImpl<MedicineMapper, Medicine> implements MedicineService {

    @Override
    public boolean saveMedicine(Medicine medicine) {
        // 这里可以添加一些业务逻辑，比如数据验证
        if (medicine.getName() == null || medicine.getName().trim().isEmpty()) {
            throw new RuntimeException("药品名称不能为空");
        }
        if (medicine.getPrice() == null || medicine.getPrice() < 0) {
            throw new RuntimeException("药品价格不能为负数");
        }

        // 调用 MyBatis-Plus 的 save 方法
        return this.save(medicine);
    }
}